﻿package top.yangyitao.action;

import javax.annotation.Resource;

import com.opensymphony.xwork2.ActionSupport;

import top.yangyitao.service.UserService;

@SuppressWarnings("serial")
public class ForgotPWD extends ActionSupport {

	@Resource
	private UserService userService;
	
	private String userName;
	private String errorMessage;
	
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}

	@Override
	public String execute() throws Exception {
		if(userName.trim().length()==0) {
			errorMessage = "*用户名不能为空!";
			return ERROR;
		}
		switch(userService.resetUserPWDByUserName(userName)) {
		case USERNOTEXIT : errorMessage = "*该用户不存在!";return ERROR;
		case UNACTIVE : errorMessage = "*该用户尚未激活!";return ERROR;
		case SUCCESS : errorMessage = "*请在3小时内前往邮箱进行重置验证";return SUCCESS;
		case EMAILERROR : errorMessage = "*这很奇怪，但是你的邮箱变得不可用了";return ERROR;
		}
		return null;
	}

}
